import 'package:flutter/material.dart';
import 'package:lib_uikit/generated/l10n.dart';
import 'package:lib_uikit/lib_uikit.dart';
import 'package:lib_uikit/resource/resources.dart';
import 'package:lib_uikit/widgets/gt_button_v3.dart';

// 空组件图标枚举类，用于区分不同的空页面选用不同的icon
enum GTEmptyIconType { data, search, hide, wallet }

/// @Title   空页面全参组件
/// @Author: bryce
/// @CreateDate: 2023年10月12日17:45:06
class GTEmptyViewV3 extends StatelessWidget {
  // icon参数，如果传了icon则下面三个icon参数不生效
  final Widget? icon;
  final String? iconAssetPath; // iconPath和iconType二选一
  final GTEmptyIconType? iconType; // iconPath和iconType二选一
  final double iconWidth;
  final double iconHeight;

  // icon下方的文案参数，如果传了titleView，则下面的title相关参数不生效
  final Widget? titleView;
  final String? title;
  final TextStyle? titleStyle;
  final double titleSize;
  final Color? titleColor;
  final FontWeight titleFontWeight;
  //底部按钮文案
  final String? buttonText;
  final VoidCallback? onButtonPressed;

  // icon和text间的间距
  final double iconTextSpace;

  final EdgeInsetsGeometry? padding;

  const GTEmptyViewV3(
      {super.key,
      this.icon,
      this.iconAssetPath,
      this.iconType,
      this.iconWidth = 96,
      this.iconHeight = 96,
      this.titleView,
      this.title,
      this.titleStyle,
      this.titleSize = 14,
      this.titleColor,
      this.titleFontWeight = FontWeight.w400,
      this.iconTextSpace = 16,
      this.padding,
      this.buttonText,
      this.onButtonPressed});

  @override
  Widget build(BuildContext context) {
    Theme.of(context);
    String? iconAssetPathReal = iconAssetPath;
    if (null == iconAssetPathReal && null != iconType) {
      switch (iconType!) {
        case GTEmptyIconType.data:
          iconAssetPathReal = Images.icEmptyData;
          break;
        case GTEmptyIconType.search:
          iconAssetPathReal = Images.icEmptySearch;
          break;
        case GTEmptyIconType.hide:
          iconAssetPathReal = Images.icEmptyHide;
          break;
        case GTEmptyIconType.wallet:
          iconAssetPathReal = Images.icEmptyWallet;
          break;
      }
    }
    return Center(
        child: Padding(
      padding: padding ?? EdgeInsets.zero,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          icon ??
              Image.asset(
                  iconAssetPath ?? (iconAssetPathReal ?? Images.icEmptyData),
                  height: iconHeight,
                  width: iconWidth),
          SizedBox(height: iconTextSpace),
          titleView ??
              Text(
                title ?? LibUIKitS.of(context).no_data,
                style: titleStyle ??
                    TextStyle(
                        color: titleColor ?? GTColorsV3.text3.color,
                        fontSize: titleSize,
                        fontWeight: titleFontWeight),
                textAlign: TextAlign.center,
              ),
          if (buttonText != null) ...[
            const SizedBox(height: 24),
            GTButtonV3(
              text: buttonText ?? "",
              onPressed: onButtonPressed,
            )
          ],
        ],
      ),
    ));
  }
}
